package org.jsola.hr.web;

import org.jsola.core.Result;
import org.jsola.hr.constant.HrConstants;
import org.jsola.hr.dto.attendschedule.AttendScheduleSaveDTO;
import org.jsola.hr.dto.attendschedule.AttendScheduleUpdateDTO;
import org.jsola.hr.service.IAttendScheduleService;
import org.jsola.hr.vo.attendschedule.AttendScheduleVO;
import org.jsola.user.core.TokenUser;
import org.jsola.user.core.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 考勤排班
 *
 * @author wxz
 */
@RestController("hrAttendScheduleController")
@RequestMapping(HrConstants.API_PATH + "/v1/attendSchedule")
public class AttendScheduleController implements IAttendScheduleControllerAPI {

    @Autowired
    private IAttendScheduleService attendScheduleService;

    @Override
    @PostMapping
    public Result<String> save(@Valid @RequestBody AttendScheduleSaveDTO attendScheduleSaveDTO) {
        TokenUser tokenUser = UserContext.getUser();
        // todo 新增考勤班次权限校验

        return Result.success(
                attendScheduleService.save(attendScheduleSaveDTO, tokenUser)
        );
    }

    @Override
    @PutMapping
    public Result<Integer> update(@Valid @RequestBody AttendScheduleUpdateDTO attendScheduleUpdateDTO) {
        TokenUser tokenUser = UserContext.getUser();
        // todo 新增考勤班次权限校验

        return Result.success(
                attendScheduleService.update(attendScheduleUpdateDTO, tokenUser)
        );
    }

    @Override
    @GetMapping(value = "selectByAttendPlanId/{attendPlanId}")
    public Result<AttendScheduleVO> selectAttendPlanId(@PathVariable String attendPlanId) {
        TokenUser tokenUser = UserContext.getUser();
        // todo 新增考勤班次权限校验

        return Result.success(
                attendScheduleService.selectAttendPlanId(attendPlanId, tokenUser.getSiteId())
        );
    }
}
